package org.demo;

import com.alibaba.fastjson.JSON;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import org.entity.Entity;
import org.util.RabbitMQUtil;

import java.util.Date;

/**
 * @author yexi
 */
public class Publisher {

    public static void main(String[] args) throws Exception {
        //1. 获取连接对象
        Connection connection = RabbitMQUtil.getConnection();

        //2. 构建Channel
        Channel channel = connection.createChannel();

        //3. 构建队列
        channel.queueDeclare("testQueue", false, false, false, null);

        //4. 发布消息
        String message = "Hello World!";
        message = JSON.toJSONString(new Entity(1L, "描述" + 1, new Date()));
        channel.basicPublish("", "testQueue", null, message.getBytes());
        System.out.println("消息发送成功！");
        connection.close();
    }
}